home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / CDTools / ClassAct / Examples / ClickTab / ClickTabExample.c < prev    next >
C/C++ Source or Header  |  1997-07-09  |  4KB  |  208 lines

  1. #define USE_BUILTIN_MATH
  2. #define USE_SYSBASE
  3.  
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <math.h>
  7.  
  8. #define    INTUI_V36_NAMES_ONLY
  9.  
  10. #include <exec/types.h>
  11. #include <exec/memory.h>
  12. #include <dos/dos.h>
  13. #include <dos/dosextens.h>
  14. #include <intuition/intuition.h>
  15. #include <intuition/gadgetclass.h>
  16. #include <intuition/intuitionbase.h>
  17. #include <intuition/classusr.h>
  18. #include <intuition/imageclass.h>
  19. #include <intuition/gadgetclass.h>
  20. #include <intuition/cghooks.h>
  21. #include <intuition/icclass.h>
  22. #include <intuition/classes.h>
  23. #include <intuition/sghooks.h>
  24. #include <graphics/gfxbase.h>
  25. #include <graphics/text.h>
  26. #include <graphics/gfxmacros.h>
  27. #include <utility/tagitem.h>
  28. #include <utility/hooks.h>
  29.  
  30. #include <clib/macros.h>
  31.  
  32. #include <proto/intuition.h>
  33. #include <proto/graphics.h>
  34. #include <proto/dos.h>
  35. #include <proto/exec.h>
  36. #include <proto/gadtools.h>
  37. #include <proto/utility.h>
  38.  
  39. #include <classact.h>
  40. #include <classact_author.h>
  41.  
  42. #include <proto/clicktab.h>
  43. #include <gadgets/clicktab.h>
  44.  
  45. struct ClassLibrary *WindowBase;
  46. struct ClassLibrary *LayoutBase;
  47. struct ClassLibrary *ClickTabBase;
  48.  
  49. #define ID_CLICKTAB        1
  50.  
  51. struct List listitems;
  52. UBYTE *names[] = 
  53. {
  54.     "Tab_1",
  55.     "Tab_2",
  56.     "Tab_3",
  57.     "Tab_4",
  58.     NULL
  59. };
  60.  
  61. BOOL ClickTabNodes(struct List *list, UBYTE **labels)
  62. {
  63.     struct Node *node;
  64.     WORD i = 0;
  65.  
  66.     NewList(list);
  67.  
  68.     while (*labels)
  69.     {
  70.         if (node = (struct Node *)AllocClickTabNode(
  71.             TNA_Text, *labels,
  72.             TNA_Number, i,
  73.             TNA_Enabled, TRUE,
  74.             TNA_Spacing, 6,
  75.             TAG_DONE))
  76.         {
  77.             AddTail(list, node);
  78.         }
  79.         labels++;
  80.         i++;
  81.     }
  82.     return(TRUE);
  83. }
  84.  
  85. VOID FreeClickTabNodes(struct List *list)
  86. {
  87.     struct Node *node, *nextnode;
  88.  
  89.     node = list->lh_Head;
  90.     while (nextnode = node->ln_Succ)
  91.     {
  92.         FreeClickTabNode(node);
  93.         node = nextnode;
  94.     }
  95.     NewList(list);
  96. }
  97.  
  98. int main( int argc, char *argv[] )
  99. {
  100.     struct Window *window;
  101.     Object *Tab_Object;
  102.     Object *Win_Object;
  103.  
  104.     /* Open the classes - typically not required to be done manually.
  105.      * SAS/C or DICE AutoInit can do this for you if linked with the
  106.      * supplied classact.lib
  107.      */
  108.     WindowBase = (struct ClassLibrary *)OpenLibrary("window.class",0L);
  109.     LayoutBase = (struct ClassLibrary *)OpenLibrary("gadgets/layout.gadget",0L);
  110.     ClickTabBase = (struct ClassLibrary *)OpenLibrary("gadgets/clicktab.gadget",0L);
  111.  
  112.     if(WindowBase && LayoutBase && ClickTabBase)
  113.     {
  114.         ClickTabNodes(&listitems, names);
  115.  
  116.         /* Create the window object.
  117.          */
  118.         Win_Object = WindowObject,
  119.             WA_ScreenTitle, "ClassAct Copyright 1995, Phantom Development LLC.",
  120.             WA_Title, "ClassAct clicktab.gadget Example",
  121.             WA_SizeGadget, TRUE,
  122.             WA_Left, 40,
  123.             WA_Top, 30,
  124.             WA_DepthGadget, TRUE,
  125.             WA_DragBar, TRUE,
  126.             WA_CloseGadget, TRUE,
  127.             WA_Activate, TRUE,
  128.             WA_SmartRefresh, TRUE,
  129.             WINDOW_ParentGroup, VLayoutObject,
  130.                 LAYOUT_SpaceOuter, TRUE,
  131.                 LAYOUT_DeferLayout, TRUE,
  132.                 StartMember, Tab_Object = ClickTabObject,
  133.                     GA_ID, ID_CLICKTAB,
  134.                     CLICKTAB_Labels, &listitems,
  135.                     CLICKTAB_Current, 0L,
  136.                 EndMember,
  137.             EndMember,
  138.         EndWindow;
  139.  
  140.         /*  Object creation sucessful?
  141.          */
  142.         if( Win_Object )
  143.         {
  144.             /*  Open the window.
  145.              */
  146.             if( window = (struct Window *) CA_OpenWindow(Win_Object) )
  147.             {
  148.                 ULONG wait, signal, result, done = FALSE;
  149.                 WORD Code;
  150.                 
  151.                 /* Obtain the window wait signal mask.
  152.                  */
  153.                 GetAttr( WINDOW_SigMask, Win_Object, &signal );
  154.  
  155.                 /* Input Event Loop
  156.                  */
  157.                 while( !done )
  158.                 {
  159.                     wait = Wait(signal|SIGBREAKF_CTRL_C);
  160.                     
  161.                     if (wait & SIGBREAKF_CTRL_C) done = TRUE;
  162.                     else
  163.  
  164.                     while ((result = CA_HandleInput(Win_Object,&Code)) != WMHI_LASTMSG)
  165.                     {
  166.                         switch (result & WMHI_CLASSMASK)
  167.                         {
  168.                             case WMHI_CLOSEWINDOW:
  169.                                 done = TRUE;
  170.                                 break;
  171.  
  172.                             case WMHI_GADGETUP:
  173.                                 switch(result & WMHI_GADGETMASK)
  174.                                 {
  175.                                     case ID_CLICKTAB:
  176.                                         break;
  177.                                 }
  178.                                 break;
  179.                         }
  180.                     }
  181.                 }
  182.             }
  183.  
  184.             /* Disposing of the window object will
  185.              * also close the window if it is
  186.              * already opened and it will dispose of
  187.              * all objects attached to it.
  188.              */
  189.             DisposeObject( Win_Object );
  190.         }
  191.     }
  192.  
  193.     FreeClickTabNodes(&listitems);
  194.  
  195.     /* Close the classes.
  196.      */
  197.     if (ClickTabBase)    CloseLibrary( (struct Library *)ClickTabBase );
  198.     if (LayoutBase)        CloseLibrary( (struct Library *)LayoutBase );
  199.     if (WindowBase)        CloseLibrary( (struct Library *)WindowBase );
  200. }
  201.  
  202. #ifdef _DCC
  203. int wbmain( struct WBStartup *wbs )
  204. {
  205.     return( main( 0, NULL ));
  206. }
  207. #endif
  208.